﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Runtime.InteropServices;

using SuperMapLib;

namespace LayoutInspection
{
    class LayoutMgmt
    {
        private AxSuperLayoutLib.AxSuperLayout superLayout = null;

        public LayoutMgmt(AxSuperLayoutLib.AxSuperLayout superLayout)
        { 
            this.superLayout = superLayout;
        }

        public bool PrintLayoutAsPDF(soLayouts objLayouts)
        {
            for (int i = 1; i <= objLayouts.Count; i++)
            {
                if (superLayout.OpenLayout(objLayouts[i]))
                {
                    Console.WriteLine("Layout:\t" + objLayouts[i]);
                    SetupPage();
                    superLayout.PrintLayout(false);
                }
                else
                {
                    return false;
                }
            }

            return true;
        }

        private void SetupPage()
        {
            if (superLayout.Page.Orientation == SuperLayoutLib.seLytOrientation.scLytLandscape)
            {
                superLayout.PaperOrientation = SuperLayoutLib.seLytOrientation.scLytLandscape;
            }
            else
            {
                superLayout.PaperOrientation = SuperLayoutLib.seLytOrientation.scLytPortrait;
            }

            superLayout.PaperMarginTop = 20;
            superLayout.PaperMarginBottom = 0;
            superLayout.PaperMarginLeft = 20;
            superLayout.PaperMarginRight = 20;
        }
    }
}
